// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/**
 * @brief
 *
 * @version  0.1
 * @author   yuanchenxi
 * @date     2024.12.21
 */

#include "Import/BDFImport/BulkData/Parameter/DAMPINGParser.h"

#include "gtest/gtest.h"

#include "Utility/Logging/SGLogger.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Parameter/IDAMPINGService.h"

#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DataStructure::FEM;
using namespace SG::DBManager;
using namespace SG::Import;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class DAMPINGTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
    }
};

TEST_F (DAMPINGTest, ParseEntry1)
{
    //                                  12345678123456781234567812345678123456781234567812345678123456781234567812345678
    std::vector<std::string> Entry = { "DAMPING      100     .02     0.1    0.03       3    0.33      NO                ",
                                       "             0.1    0.11   0.111            " };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseDAMPING (DB_SERVICEFACTORY, dividedEntryInfo);

    std::vector<SG::DataStructure::FEM::DAMPINGData> tempData;
    DB_SERVICEFACTORY->get<IDAMPINGService> ()->FindBySId (100, tempData);

    SG::DataStructure::FEM::DAMPINGData tempData2;
    tempData2.m_sId    = 100;
    tempData2.m_G      = 0.02;
    tempData2.m_ALPHA1 = 0.1;
    tempData2.m_ALPHA2 = 0.03;
    tempData2.m_HYBRID = 3;
    tempData2.m_GEFACT = 0.33;
    std::memcpy (tempData2.m_ROTSEP, "NO\0\0", 4);
    tempData2.m_W3       = 0.1;
    tempData2.m_W4       = 0.11;
    tempData2.m_WH       = 0.111;
    tempData2.m_domainId = 1;

    SGInfo << tempData.size ();
    ASSERT_TRUE (tempData2 == tempData[0]);
}

TEST_F (DAMPINGTest, ParseEntry2)
{
    //                                  12345678123456781234567812345678123456781234567812345678123456781234567812345678
    std::vector<std::string> Entry = { "DAMPING      101     .02     0.1    0.03       3    0.33                        ",
                                       "             0.1    0.11   0.111            " };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseDAMPING (DB_SERVICEFACTORY, dividedEntryInfo);

    std::vector<SG::DataStructure::FEM::DAMPINGData> tempData;
    DB_SERVICEFACTORY->get<IDAMPINGService> ()->FindBySId (101, tempData);

    SG::DataStructure::FEM::DAMPINGData tempData2;
    tempData2.m_sId    = 101;
    tempData2.m_G      = 0.02;
    tempData2.m_ALPHA1 = 0.1;
    tempData2.m_ALPHA2 = 0.03;
    tempData2.m_HYBRID = 3;
    tempData2.m_GEFACT = 0.33;
    std::memcpy (tempData2.m_ROTSEP, "YES\0", 4);
    tempData2.m_W3       = 0.1;
    tempData2.m_W4       = 0.11;
    tempData2.m_WH       = 0.111;
    tempData2.m_domainId = 1;
    ASSERT_TRUE (tempData2 == tempData[0]);
}
